package com.example.administrator.yuejian2.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.bean.CourseBean;
import com.example.administrator.yuejian2.viewholder.CourseViewHolder;
import com.squareup.picasso.Picasso;

import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

import static com.example.administrator.yuejian2.other.Url.IMAGEURL;
import static com.example.administrator.yuejian2.other.Url.VIDEOIMAGEURL;
import static com.example.administrator.yuejian2.other.Url.VIDEOURL;

public class CourseAdapter extends RecyclerView.Adapter {

    private Context context;
    private LayoutInflater layoutInflater;
    private List<CourseBean> list;
    public CourseAdapter(Context context){
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }

    public void courseData(List<CourseBean> list)
    {
        this.list=list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.course_item,parent,false);
        return new CourseViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        CourseViewHolder courseViewHolder=(CourseViewHolder)holder;
        CourseBean bean=list.get(position);
        courseViewHolder.course_name.setText(bean.getCourse_name());
        courseViewHolder.course_price.setText(bean.getCourse_price());
        if (  courseViewHolder.player != null) {
            courseViewHolder.player.release();
        }

        boolean setUp = courseViewHolder.player.setUp(VIDEOURL, JCVideoPlayer.SCREEN_LAYOUT_LIST, "");
        if (setUp) {
            Glide.with(context).load(VIDEOIMAGEURL).into(courseViewHolder.player.thumbImageView);
        }

    }

    @Override
    public int getItemCount() {
        if (list==null)
        {
            return 0;
        }
        else
        {
            return  list.size();
        }
    }
}
